def cal_square(length,width):
    return length * width
result = cal_square(4,3)
print(result)


def borrow_books(name,book,day):
    print(f"{name}借阅了书籍《{book}》,预计借阅{day}天")
borrow_books("小千","红楼梦",14)
borrow_books("小峰","西游记",10)


def borrow_books(name,book,day):
    print(f"{name}借阅了书籍《{book}》,预计借阅{day}天")
borrow_books("小千","红楼梦",14)
result = borrow_books("小峰","西游记",10)
print(result)


def number_max(a,b):
    if a>b:
        return a
    else:
        return b
    print("函数执行完成")
result = number_max(3,5)
print(result) 


def cal_digit(number):
    high = number // 100
    mid = number // 10 % 10
    low = number % 10
    return high, mid, low
result = cal_digit(543)
print(result)
a,b,c =cal_digit(543)
print(a,b,c)


def is_leap(year):


    """
    判断年份是不是闰年

    """
    if (year%4 == 0 and year%100!=0) or year%400 == 0:
        return True
    else:
        return False
    
result = is_leap(2024)
print(result)

#print(is_leap.__doc__)    


def favorite_place(name,place):
    print(f"我的名字是{name}")
    print(f"我最喜欢的名胜古迹是{place}")
favorite_place("小千","万里长城")  
favorite_place(place="桂林山水",name="小峰") 


def favorite_place(name,place="万里长城"):
    print(f"我的名字是{name}")
    print(f"我最喜欢的名胜古迹是{place}")  
favorite_place("小峰")


def favorite_language(name,*languages):
    print(f"{name}喜欢的编程语言如下：")
    print(languages)
favorite_language("小千","Python")
favorite_language("小峰","C","C++","Python")  


def personinfo(**info):
    return info
result = personinfo(id = 1,name = "李昀佳",age = 20,grade = "大三")
print(result)


def personinfo(*languages,**info):
    for key,value in info.items():
        print(f"{key}:{value}")
    print("喜欢的编程如下：")
    for language in languages:
        print(language,end=" ")    
    
    return info
result = personinfo("C","C++","Python",id = 1,name = "李昀佳",age = 20,grade = "大三")
print(result)


def product(a,b,c):
    return a * b * c
tuple01 = (22,10,22)
print(product(*tuple01))
list01 = [22,10,22]
print(product(*list01))
dict01 = {
    "a":22,
    "b":10,
    "c":22,
}
print(product(**dict01))


def join_str(brand_str):
    brand_str = "www." + brand_str + ".com"
    return brand_str
brand = "codingke"
url = join_str(brand)
print("品牌名称为：",brand)
print("网址为：",url)


def change_shelves(good_list):
    good_list.append("礼盒")
    return good_list
alist = ["牛奶","薯片","巧克力"]
result = change_shelves(alist.copy())
print(alist)
print(result)


def is_even(number):
    if number%2 == 0:
        return True
    else:
        return False
    
result = is_even(3) 
print(result)  


import math
def is_prime(number):
    if number < 2:
        return False
    sqrt_number = int(math.sqrt(number))
    for i in range(2, sqrt_number + 1):
        if number % i == 0:
            return False
    return True    



def can_split(number):
    equo_list=[]
    for i in range(1,number//2+1):
        j=number-i
        if is_prime(i) and is_prime(j):
            equo_list.append(f"{number}={i}+{j}")
        if not equo_list:
            equo_list.append(f"{number}无法分解成两个素数")
        return equo_list





import math
def is_even(number):
    """判断一个数是不是偶数"""
    if number%2 == 0:
        return True
    else:
        return False
def is_prime(number):
    """判断一个数是不是素数"""
    if number<2:
        return False
    sqrt_number=int(math.sqrt(number))
    for i in range(2,sqrt_number+1):
        if number%i == 0:
            return False
    return True
def can_split(number):
    """判断一个数能否分解成两个素数的和，返回一个列表"""
    equo_list=[]
    for i in range(1,number//2+1):
        j=number-i
        if is_prime(i) and is_prime(j):
            equo_list.append(f"{number}={i}+{j}")
        if not equo_list:
            equo_list.append(f"{number}无法分解成两个素数")
        return equo_list
if __name__=="__main__":
    random_num=input("请输入一个大于5的偶数")
    if random_num.isdigit():
        random_num=int(random_num)
        if random_num>5 and is_even(random_num):
            result_list=can_split(random_num)
            for equo in result_list:
                print(equo)
        else:
            print("输入的数字不符合要求！")
    else:
        print("请输入整数！")





def person_name(name):
    print("宠物主人的名字是：",name)
def pet_name(name):
    print("宠物的名字是：",name)
person_name("小千")
person_name("旺财")


x = 3
def func():
    print(x)
func()


x = 3
def func():
    x = x+2
    print(x)
func()
#\ No newline at end of file
    
x=3
def func():
    global x
    x = x+2
    print(x)
func()

stu_dict={
    "name":"小千",
    "stu_id":202101,
    "grade":"大二",
}
def change_grade():
    stu_dict["grade"]="大三"
change_grade()
print(stu_dict)


stu_dict={
    "name":"小千",
    "stu_id":202101,
    "grade":"大二",
}
def change_grade():
    stu_dict["grade"]="大三"
    print("change_grade()函数内的stu_dict：",stu_dict)
change_grade()
print("全局变量stu_dict：",stu_dict)


def join_str(brand_str):
    brand_str="www."+brand_str+".com"
    print("局部变量：",locals)
    return brand_str
brand="codingke"
url=join_str(brand)
print("全局变量：",globals())


def func02():
    print("func02()函数开始")
    def func01():
        print("func01()函数开始")
        print("func01()函数结束")
    func01()
    print("func02()函数结束")
func02()


def func02():
    x = 5
    def func01():
        print(x)
    func01()
func02()


def func02():
    x = 5
    def func01():
        nonlocal x
        x=x+1
    func01()
    print(x)
func02()



def cal_factorial(n):
    if n == 0:
        return 1
    return n*cal_factorial(n-1)
number=int(input("请输入一个非负整数："))
print(cal_factorial(number))



def cal_power(x,n):
    if n == 0:
        return 1
    return x*cal_power(x,n-1)
result=cal_power(2,3)
print(result)


def partition(array,low,high):
    """
    分解过程
    :param array:整体数据
    :param low:数据的左端
    :param high:数据的右端
    return:基准的位置
    """
    left=low-1
    pivot=array[high]
    for right in range(low,high):
        if array[right]<=pivot:
            left=left+1
            array[left],array[right]=array[right],array[left]
    array[left+1],array[high]=array[high],array[left+1]
    return left+1
def quickSort(array,low,high):
     """
    快速排序函数，无返回值，直接改变列表内容
    :param array:整体数据
    :param low:数据的左端
    :param high:数据的右端
    """
     if low<high:
         pivot=partition(array,low,high)
         quickSort(array,low,pivot-1)
         quickSort(array,pivot+1,high)
if __name__=="__main__":
    list01=[9,3,1,5,8,6,2,4]
    quickSort(list01,0,len(list01)-1)
    print(list01)  